home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr10
/
piglat10.zip
/
PIGLATIN.L
< prev
Wrap
Text File
|
1993-06-16
|
3KB
|
149 lines
/* piglatin.l */
/* piglatin version 1.00
** 06/16/93
** Duane Paulson <ci922@cleveland.freenet.edu> "dap"
** Piglatin text filter.
**
** NOTE that this program was developed using FLEX, not LEX.
** When compiling using lex, some tweaking of the %e, %p, %n,
** %n, %k, %a, and %o parameters may be necessary. Since flex
** does not use these parameters, I cannot generate recommended
** values. Hint: If you get the "Parse tree to big" lex error
** message, you can fix it by tweaking these parameters.
** I suggest you run the MAN page for lex, or locate the
** flex code and use that.
**
** Public domain. Use at your own risk.
*/
/*************************************************************************
REVISION LOG
when ver who change
-------- ---- --- -----------------------------------------------------
06/16/93 1.00 dap Initial release.
*************************************************************************/
LETTER [A-Za-z'\-]
VOWEL [AEIOUaeiou]
CONSONANT [A-DF-HJ-NP-TV-Za-df-hj-np-tv-z'\-]
SW [ \t\"(\[{\.,!?:;_*]
EW [ \t\.,\"\]}!?):;_*]
#define PUTLAST unput(*(yytext+strlen(yytext)-1));\
*(yytext+strlen(yytext))='\0';
#define MASKIT mask=*(yytext+strlen(yytext)-1)&32;
#define PUT_AY fputc('A'|mask, yyout); fputc('Y'|mask, yyout);
#define PUT_WAY fputc('W'|mask, yyout); PUT_AY;
#include <string.h>
#include <ctype.h>
int mask;
char cons[128];
int conlen;
#ifdef __STDC__
void put_midstring(int start);
void strip_cons(int start);
#else
int put_midstring();
int strip_cons();
#endif
%%
{SW}-+{EW} |
^-+{EW} PUTLAST; ECHO;
^-+$ |
{SW}-+$ ECHO;
^{VOWEL}{LETTER}*{EW} |
{SW}{VOWEL}{LETTER}*{EW} {
PUTLAST;
MASKIT;
ECHO;
PUT_WAY;
}
^{VOWEL}{LETTER}*$ |
{SW}{VOWEL}{LETTER}*$ {
MASKIT;
ECHO;
PUT_WAY;
}
{SW}{CONSONANT}{LETTER}*{EW} {
PUTLAST;
MASKIT;
fputc(*yytext, yyout);
strip_cons(1);
put_midstring(1+conlen);
}
{SW}{CONSONANT}{LETTER}*$ {
MASKIT;
fputc(*yytext, yyout);
strip_cons(1);
put_midstring(1+conlen);
}
^{CONSONANT}{LETTER}*{EW} {
PUTLAST;
MASKIT;
strip_cons(0);
put_midstring(conlen);
}
^{CONSONANT}{LETTER}*$ {
MASKIT;
strip_cons(0);
put_midstring(conlen);
}
%%
#ifdef __STDC__
void strip_cons(int start)
#else
strip_cons(start)
int start;
#endif
{
conlen=0;
while(strchr("bcdfghjklmnpqrstvwxyz", tolower(*(yytext+start)))!=NULL)
{
*(cons+conlen)=*(yytext+start);
start++;
conlen++;
}
*(cons+conlen)='\0';
}
#ifdef __STDC__
void put_midstring(int start)
#else
put_midstring(start)
int start;
#endif
{
if(strlen(yytext)>start)
fputc(toupper(*(yytext+start))|
(*(yytext+start-conlen)&32), yyout);
if(strlen(yytext)>(start+1))
fprintf(yyout, "%s", yytext+start+1);
fputc(toupper(*cons)|mask, yyout);
conlen=1;
while(*(cons+conlen)!='\0')
{
fputc(toupper(*(cons+conlen))|mask, yyout);
conlen++;
}
PUT_AY;
}
main()
{
yylex();
}